package com.ruoyi.train.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ruoyi.train.domain.TrainClass;
import com.ruoyi.train.service.ITrainClassService;


/**
 * 培训班级Controller
 * 
 * @author wusihao
 * @date 2023-03-20
 */
@Api(tags = "班级信息", value = "班级信息接口")
@RestController
@CrossOrigin
@RequestMapping("/class")
public class TrainClassController extends BaseController
{
    @Autowired
    private ITrainClassService trainClassService;

    /**
     * 查询培训班级列表
     */
    @ApiOperation("查询班级培训列表")
    @GetMapping("trainPlan/{trainId}")
    public TableDataInfo list(@PathVariable Long trainId)
    {
        startPage();
        List<TrainClass> list = trainClassService.selectTrainClass(trainId);
        return getDataTable(list);
    }

    /**
     * 导出培训班级列表
     */
    @ApiOperation("导出培训班级列表")
    @Log(title = "培训班级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainClass trainClass)
    {
        List<TrainClass> list = trainClassService.selectTrainClassList(trainClass);
        ExcelUtil<TrainClass> util = new ExcelUtil<TrainClass>(TrainClass.class);
        util.exportExcel(response, list, "培训班级数据");
    }

    /**
     * 获取培训班级详细信息
     */
    @ApiOperation("获取培训班级详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(trainClassService.selectTrainClassById(id));
    }

    /**
     * 新增培训班级
     */
    @ApiOperation("新增培训班级")
    @Log(title = "培训班级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainClass trainClass)
    {
        return toAjax(trainClassService.insertTrainClass(trainClass));
    }

    /**
     * 修改培训班级
     */
    @ApiOperation("修改培训班级")
    @Log(title = "培训班级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainClass trainClass)
    {
        return toAjax(trainClassService.updateTrainClass(trainClass));
    }

    /**
     * 删除培训班级
     */
    @ApiOperation("删除培训班级")
    @Log(title = "培训班级", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(trainClassService.deleteTrainClassByIds(ids));
    }

    /**
     * 培训班级结束
     */
    @ApiOperation("培训班级结束")
    @Log(title = "培训班级", businessType = BusinessType.DELETE)
    @GetMapping ("/trainEnd/{id}")
    public AjaxResult trainEnd(@PathVariable Long id)
    {
        return toAjax(trainClassService.trainEnd(id));
    }
}
